package leetcode.simple._previous;

public class MergeTwoLists {

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode node = new ListNode(0);
        ListNode pre = node;
        while (l1 != null && l2 != null) {
            if (l1.val > l2.val) {
                pre.next = new ListNode(l1.val);
                l1 = l1.next;
            }else {
                pre.next = new ListNode(l2.val);
                l2 = l2.next;
            }

            pre = pre.next;
        }

        if (l1 == null) pre.next = l2;
        else pre.next = l1;

        return node.next;
    }
}
